/*
 * @Author: luoqi
 * @Date: 2021-05-26 16:10:26
 * @Last Modified by: luoqi
 * @Last Modified time: 2022-11-25 00:40:28
 */

#include <string.h>
#include "qterm.h"

static QCliObj qshell;

int qterm_init(void)
{
    return qcli_init(&qshell, bsp_printf);
}

int qterm_exec(char c)
{
    return qcli_exec(&qshell, c);
}

int qterm_call(char *args)
{
    return qcli_exec_str(&qshell, args);
}

int qterm_attach(QCliCmd *cmd, const char *name, QCliCallback callback, const char *usage)
{
    return qcli_add(&qshell, cmd, name, callback, usage);
}

int qterm_detach(QCliCmd *cmd)
{
    return qcli_remove(&qshell, cmd);
}

int isarg(const char *s, const char *arg)
{
    return strcmp(s, arg);
}

int qterm_help(QCliArgsEntry *table, uint32_t sz)
{
    uint32_t n = sz / sizeof(QCliArgsEntry);
    for(uint32_t i = 0; i < n; i++) {
        QSH(" -%s %s\r\n", table[i].name, table[i].help);
    }
    return 0;
}
